#pragma once

#include <map>
#include "common/PSingleton.h"
#include "common/LSocket.h"
#include "common/PThreadManager.h"
#include "common/PDefineFunction.h"
#include "ILogicPerson.h"
#include "entity/GLBody.h"
#include "entity/GLGroup.h"
#include "entity/GLMap.h"

class CGLGoodsBase;
class CGLGoodsWeapon;
class CGLGoodsCommodity;
class CGLGoodsProperty;
class CGLGoodsTrade;

class CLogicData : public CSingleton<CLogicData>
{
		QUEUE_OBJ_PTR_FUNC_INIT_1(CGLGoodsBase, Goods)
		QUEUE_OBJ_PTR_FUNC_INIT_1(CGLGoodsWeapon, Weapon)
		QUEUE_OBJ_PTR_FUNC_INIT_1(CGLGoodsCommodity, Commodity)
		QUEUE_OBJ_PTR_FUNC_INIT_1(CGLGoodsProperty, GoodsProp)
		QUEUE_OBJ_PTR_FUNC_INIT_1(CGLGoodsTrade, GoodsTrade)

		typedef std::map<uint64_t, CGLBody*>			MapBody_t;
public:
		typedef std::map<uint64_t, AnimalLookInfo>		MapTempGroup_t;
		typedef std::vector<uint32_t>					VecUI32_t;
		enum ChangeStatus {
			CSUserInfo,
			CSUserBattleSkill,
			CSUserLifeSkill,
			CSTotalCount,
		};
public:
	CLogicData(void);
	~CLogicData(void);
	bool CheckUpdate();
	bool LoadServerList();
	bool InitBase();
	bool InitInfo();
	bool Init();

	LSocket* GetLogicConnect() { return &m_LogicConnect; }
	CILogicPerson* GetOneself() { return m_Oneself; }
	void AddMyBody(uint64_t bid, CGLBody* body);
	void DelMyBody(uint64_t bid);
	CGLBody* GetMyBody(uint64_t bid) const;

	void SetChangeStatus(ChangeStatus status) { m_ChangeStatus[status]++; }
	uint32_t GetChangeStatus(ChangeStatus status) const { return m_ChangeStatus[status]; }

	CGLGroup* GetGroup() const { return m_Group; }
	CGLGroup* CreateGroup() { m_Group = new CGLGroup; return m_Group; }
	void RemGroup() { if (nullptr != m_Group) { delete m_Group; m_Group = nullptr; } }

	CGLMap* GetCurMap() { return &m_Map; }

	void AddTempGroup(const AnimalLookInfo& info) { m_TempGroup[info.m_Uid] = info; }
	void DelTempGroup(const AnimalLookInfo& info) { m_TempGroup.erase(info.m_Uid); }
	MapTempGroup_t& GetTempGroup() { return m_TempGroup; }
private:
	LSocket					m_LogicConnect;

	CILogicPerson*			m_Oneself;
	MapBody_t				m_MyBodys;
	VecUI32_t				m_ChangeStatus;

	/************************************************************************/
	/*                                                                      */
	/************************************************************************/
	MapTempGroup_t			m_TempGroup;
	CGLGroup*				m_Group;
	CGLMap					m_Map;
};

